package com.hongdee.market.bc.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.EntityUtils;
import com.hongdee.market.bc.entity.TBcCustomeItem;
import com.hongdee.market.bc.service.ITBcCustomItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by dell on 2017/5/15.
 */
@RestController
@RequestMapping("/bc/custome/item")
public class TBcCustomeItemController {
    @Autowired
    private ITBcCustomItemService itBcCustomItemService;

    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestBody TBcCustomeItem tBcCustomeItem) throws Exception {
        EntityUtils.valid(tBcCustomeItem);
        TBcCustomeItem group = itBcCustomItemService.saveOrUpdate(tBcCustomeItem);
        ResultEntity res = new ResultEntity();
        res.setData(group);
        res.setSuccess(true);
        res.setMsg("保存成功！");
        return res;
    }

    /*
    * 查询
    * */
    @RequestMapping("/info")
    @ResponseBody
    public ResultEntity info(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "id", defaultValue = "") String id) throws Exception {
        EntityUtils.valid(id);
        ResultEntity res = new ResultEntity();
        Map map = itBcCustomItemService.info(id);
        res.setData(map);
        res.setSuccess(true);
        res.setMsg("查询详情成功");
        return res;
    }

    /**
     * 停用
     */
    @RequestMapping("/stop")
    @ResponseBody
    public ResultEntity stop(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "id", defaultValue = "0") String id) throws Exception {
        EntityUtils.valid(id);
        ResultEntity res = new ResultEntity();
        itBcCustomItemService.update(id, "0");
        res.setSuccess(true);
        res.setMsg("停用成功！");
        return res;
    }

    /**
     * 停用
     */
    @RequestMapping("/start")
    @ResponseBody
    public ResultEntity start(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token,
                              @RequestParam(name = "id", defaultValue = "0") String id) throws Exception {
        EntityUtils.valid(id);
        ResultEntity res = new ResultEntity();
        itBcCustomItemService.update(id, "1");
        res.setSuccess(true);
        res.setMsg("启动成功！");
        return res;
    }

    /*
    * 分页
    * */
    @RequestMapping("/page")
    @ResponseBody
    public Map newPage(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token,
                       @RequestParam(name = "start", defaultValue = "0") String start,
                       @RequestParam(name = "limit", defaultValue = "50") String limit,
                       @RequestParam(name = "searchValue", defaultValue = "") String searchValue
    ) throws Exception {
        Map map = this.itBcCustomItemService.newPage(start, limit, searchValue);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 评分项目下拉框
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/combo")
    @ResponseBody
    public List<Map> combo() throws Exception {
        return this.itBcCustomItemService.combo();
    }

    /**
     * 评分项目转换框
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("/convert")
    @ResponseBody
    public Map convert() throws Exception {
        return this.itBcCustomItemService.convert();
    }

}
